<template>
	<public-view navColor="#ffffff" topBgShow="3" navType="shop" navTitle="配件">
		<view class="content">
			<view class="left-scoll-view">
				<scroll-view scroll-y="true" class="scroll-left">
					<view class="w-100 flex f-d-c a-i-c">
						<!-- <block v-for="(item, index) in class_list" :key="index"> -->
							<block v-for="(itm, idx) in class_list" :key="idx">
								<view class="item all-center" @click="changeClass(itm)" :class="page_class_id === itm.id?'active':'unactive'">
									{{itm.name}}
								</view>
							</block>
						<!-- </block> -->
					</view>
					<!-- <view class="w-100 flex f-d-c a-i-c" v-else>
						<view class="item all-center unactive" @click="changeshowChildren">
							<image class="n-icon" src="@/static/images/back-icon-nav.svg" mode=""></image>
							返回
						</view>
						<block v-for="(itm, idx) in chilldren_list" :key="idx">
							<view class="item all-center" @click="changeClassChildren(itm)" :class="class_id === itm.id?'active':'unactive'">
								{{itm.name}}
							</view>
						</block>
					</view> -->
				</scroll-view>
			</view>
			<view class="right-scroll-box">
				<scroll-view scroll-y="true" class="scroll-right">
					<view class="right-after flex w-100 j-c-b f-w-w">
						<block v-for="(item, index) in chilldren_list" :key="index">
							<view class="item flex f-d-c a-i-c color-333 f-w-b f-s-22 l-h-30" @click="goToUrl(item)">
								<image class="image" :src="item.image" mode=""></image>
								{{item.name||""}}
							</view>
						</block>
					</view>
				</scroll-view>
			</view>
		</view>
	</public-view>
	
</template>

<script>
	import {getStorClassList,getGoodsList} from "@/utils/pagePublic.js"
	import {goTo} from "@/nav.js"
	export default {
		data() {
			return {
				class_id:0,
				class_list:[],
				top_goods_list:[],
				page_class_id:-1,
				page_pid:0,
				chilldren_list:[],
				show_children:false
			};
		},
		onLoad(o) {
			console.log(o)
			if(o.class_id){
				this.page_class_id = Number(o.class_id)
				// this.class_id = this.page_class_id
			}
			if(o.pid){
				this.page_pid = Number(o.pid)
			}
		},
		onShow() {
			this.getClassList()
		},
		methods:{
			goTo,
			changeshowChildren(){
				this.show_children = false
			},
			goToUrl(item){
				console.log(item)
				this.goTo({url:`/pages/shop/goodsLIst?top_class_id=${this.page_class_id}&class_id=${item.id}`})
				// let str = JSON.stringify(item)
				// this.$store.commit("changeGoodsInfo",str)
				// this.goTo({url:'/pages/shop/goodsInfo'})
			}, 
			getGoodsListMethods(){
				getGoodsList({
					merchant_id:"",
					class_id:this.class_id,
					top_class_id:this.page_class_id,
					keyword:""
				},res=>{
					console.log(res)
					this.top_goods_list = res.data.data
				})
			},
			getClassList(){
				let that = this
				that.util.postRequest({
					url:"v1/merchant/getPartsClass",
					data:{
						disposable:true
					}
				}).then(res=>{
					console.log(res)
					that.class_list = res.data
					if(that.page_class_id !==-1){
						for(let item of that.class_list){
							if(that.page_class_id === item.id){
								that.getClassList1()
								break
							}
						}
					}else{
						that.chilldren_list = that.class_list[0].children
						that.class_id = that.chilldren_list[0].id
					}
				})
			},
			getClassList1(){
				let that = this
				that.util.postRequest({
					url:"v1/merchant/getPartsClass",
					data:{
						pid:this.page_class_id
					}
				}).then(res=>{
					console.log(res)
					if(res.data.length>0){
						that.chilldren_list = res.data
						that.class_id = that.chilldren_list[0].id
						that.show_children = true
					}else{
						that.class_id = 0
						that.show_children = false
					}
					// that.getGoodsListMethods()
				})
			},
			changeClassChildren(item){
				if(item.id === this.class_id) return
				this.class_id = item.id
				this.top_goods_list = []
				// this.getGoodsListMethods()
			},
			changeClass(item){
				this.page_class_id = item.id
				this.chilldren_list = []
				this.top_goods_list = []
				if(item.id !== -1){
					this.getClassList1()
				}else{
					this.chilldren_list = this.class_list[0].children
					this.class_id = this.chilldren_list[0].id
				}
				// this.getGoodsListMethods()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.right-scroll-box{
		width: 560upx;
		height: 88vh;
		background: #FFFFFF;
		border-radius: 0px 16upx 0px 0px;
		.scroll-right{
			width: 100%;
			height: 100%;
			.right-after{
				padding: 20upx 34upx;
				&::after{
					width: 156upx;
					content: " ";
				}
				.item{
					margin-bottom: 24upx;
					.image{
						width: 156upx;
						height: 156upx;
						border-radius: 20upx;
						background: #fafafa;
						margin-bottom: 22upx;
					}
				}
			}
		}
	}
	.left-scoll-view{
		width: 142upx;
		height: 88vh;
		background: #F4F4F4;
		border-radius: 16upx 0px 0px 0px;
		.scroll-left{
			width: 100%;
			height: 100%;
			.item{
				width: 100%;
				height: 78upx;
				border-radius: 16upx 0 0 16upx;
				font-size: 24upx;
				transition: all .2s ease-out;
			}
			.active{
				background-color: #FFFFFF;
				font-weight: bold;
				
			}
		}
	}
	.content{
		width: 750rpx;
		display: flex;
		padding: 22rpx 24upx 0;
	}
	.n-icon{
		height: 20rpx;
		width: 24rpx;
		margin-right: 10rpx;
	}
</style>
